import java.io.PrintStream;
import java.lang.reflect.Constructor;
import network.X2;
import network.X3;
import network.X6;
import network.X7;
import player.MachinePlayer;
import player.Player;

final class Network
{
  static final double ooox = 5.5D;
  static double time = 0.0D;
  static boolean quit = false;
  static boolean waitKey = false;
  static int optionOffset = 0;

  private static String playGame(String[] paramArrayOfString, int paramInt, boolean paramBoolean)
  {
    if (paramBoolean) {
      paramInt = 0;
      if (Math.random() * 2.0D < 1.0D) {
        paramInt = 1;
      }

    }

    Object localObject1 = null; Object localObject2 = null;
    try
    {
      String str1 = paramArrayOfString[optionOffset].toLowerCase();
      if (str1.equals("machine")) {
        localObject1 = new MachinePlayer(paramInt);

        ((Player)localObject1).myName = "MachinePlayer";
      }
      else if (str1.equals("human")) {
        localObject1 = new X6(paramInt);
        ((Player)localObject1).myName = "HumanPlayer";
      }
      else if (str1.equals("random")) {
        localObject1 = new X7(paramInt);
        ((Player)localObject1).myName = "RandomPlayer";
      }
      else {
        localObject1 = (Player)Class.forName(paramArrayOfString[optionOffset] + ".MachinePlayer").getConstructor(new Class[] { Integer.TYPE }).newInstance(new Object[] { new Integer(paramInt) });

        ((Player)localObject1).myName = paramArrayOfString[optionOffset];
      }

      String str2 = paramArrayOfString[(optionOffset + 1)].toLowerCase();
      if (str2.equals("machine")) {
        localObject2 = new MachinePlayer(X2.ooxxx(paramInt));

        ((Player)localObject2).myName = "MachinePlayer";
      }
      else if (str2.equals("human")) {
        localObject2 = new X6(X2.ooxxx(paramInt));
        ((Player)localObject2).myName = "HumanPlayer";
      }
      else if (str2.equals("random")) {
        localObject2 = new X7(X2.ooxxx(paramInt));
        ((Player)localObject2).myName = "RandomPlayer";
      }
      else {
        localObject2 = (Player)Class.forName(paramArrayOfString[(optionOffset + 1)] + ".MachinePlayer").getConstructor(new Class[] { Integer.TYPE }).newInstance(new Object[] { new Integer(X2.ooxxx(paramInt)) });

        ((Player)localObject2).myName = paramArrayOfString[(optionOffset + 1)];
      }

      if (paramArrayOfString.length >= optionOffset + 4) {
        ((Player)localObject2).myName = paramArrayOfString[(optionOffset + 3)];
      }
      if (paramArrayOfString.length >= optionOffset + 3) {
        ((Player)localObject1).myName = paramArrayOfString[(optionOffset + 2)];
      }
      else if (((Player)localObject1).myName.equals(((Player)localObject2).myName))
        ((Player)localObject2).myName = "Second ".concat(((Player)localObject2).myName);
    }
    catch (Exception localException)
    {
      System.err.println(localException);
    }

    X3 localX3 = null;
    if (paramInt == 1)
      localX3 = new X3((Player)localObject1, (Player)localObject2, true, time);
    else {
      localX3 = new X3((Player)localObject2, (Player)localObject1, true, time);
    }

    if (paramBoolean) {
      localX3.forceInitialMove();
    }

    X3.setWait(waitKey);

    while (localX3.xooox()) {
      try {
        Thread.sleep(200L); } catch (InterruptedException localInterruptedException) {
      }
      localX3.oxxxo();
    }

    return (String)(String)localX3.xxoooName;
  }

  public static void main(String[] paramArrayOfString) {
    int i = 0;

    int j = 0;
    if (Math.random() * 2.0D < 1.0D) {
      j = 1;
    }

    if (paramArrayOfString.length < 2) {
      System.out.println("Usage: java Network [-q] [-t <time>] <playerlogin1> <playerlogin2> [<team1>] [<team2>]");
      System.exit(1);
    }

    if (paramArrayOfString[optionOffset].equals("-q")) {
      quit = true;
      optionOffset += 1;
    }
    if (paramArrayOfString[optionOffset].equals("-r")) {
      i = 1;
      time = 5.5D;
      waitKey = true;
      optionOffset += 1;
    }
    if (paramArrayOfString[optionOffset].equals("-t")) {
      time = new Double(paramArrayOfString[(++optionOffset)]).doubleValue();
      System.out.println("Time limit set to: " + time);
      optionOffset += 1;
    }

    if (i != 0) {
      Object localObject = null; String str1 = null; String str2 = null;
      try {
        System.out.println("--------  Match 1  ---------");
        localObject = playGame(paramArrayOfString, 1, false); } catch (Exception localException2) {
        localException2.printStackTrace();
      }try {
        System.out.println("--------  Match 2  ---------");
        str1 = playGame(paramArrayOfString, 0, false); } catch (Exception localException3) {
        localException3.printStackTrace();
      }

      if (!((String)localObject).equals(str1)) {
        try {
          System.out.println("--------  Match 3  ---------");
          str2 = playGame(paramArrayOfString, 0, true); } catch (Exception localException4) {
          localException4.printStackTrace();
        }
      }

      if (str1.equals(str2)) {
        localObject = str1;
      }
      if (((String)localObject).equals(paramArrayOfString[optionOffset]))
        str1 = paramArrayOfString[optionOffset];
      else {
        str1 = paramArrayOfString[(optionOffset + 1)];
      }
      System.out.println("--------  MATCH WINNER  ---------");
      System.out.println("Login: " + str1 + ", Team: " + (String)localObject);
      System.out.println("--------  MATCH WINNER  ---------");
      System.out.println();
    }
    else
    {
      try
      {
        playGame(paramArrayOfString, 1, false); } catch (Exception localException1) {
        localException1.printStackTrace();
      }
    }

    if (quit)
      System.exit(0);
  }
}